package com.wc.AlgoOJ._暴力.CT0105;

import java.util.Locale;
import java.util.Scanner;

/**
 * @Author congge
 * @Date 2023/11/26 19:12
 * 听写字符串
 * http://43.138.190.70:8888/p/CT0105
 * @description
 */
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        String s = sc.nextLine();
        s = s.toUpperCase(Locale.ROOT);

        char[] chs = s.toCharArray();
        int len = chs.length;
        StringBuffer ans = new StringBuffer();
        /**
         * 判断是否插入头部
         */
        boolean flg;
        for (int i = 0; i < len; i++) {
            int idx = 0;
            flg = false;
            // 相等就往后比较
            while (idx < i && ans.charAt(idx) == chs[i]) {
                idx++;
            }
            // 看看是否比到最后一个了
            if (idx != i) {
                flg = ans.charAt(idx) < chs[i];
            }
            if (flg) {
                ans.insert(0, chs[i]);
            } else {
                ans.append(chs[i]);
            }
        }
        System.out.println(ans);
    }
}
